<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
<<<<<<< HEAD
//引入Storage
use Storage;
class UploaderController extends Controller
{
    //webuploader方法
    public function webuploader(Request $requset) {
    	//对上传文件进行处理
    	//1、判断文件是否上传成功
    	if($requset -> hasFile('file') && $requset -> file('file') -> isValid()) {
    		//2 重命名文件
    		$filename = sha1($requset -> file('file') -> getClientOriginalName() . time() . rand(1000,9999)) . '.' .$requset -> file('file') -> getClientOriginalExtension();
    		//3 保存上传文件
    		Storage::disk('public') -> put($filename,file_get_contents($requset -> file('file') -> path()));
    		return response() -> json([
    				'errorCode'  => '0',
    				'message'  => '文件上传成功',
    				'path'  => '/storgae/' . $filename
    			]);
    	} else {
    		//4给ajax一个响应
    		return response() -> json([
    				'errorCode'   => '1',
    				'message'   => $requset -> file('file') -> getErrorMessage(),
    			]);
    	}
=======
use Storage;

class UploaderController extends Controller
{
    //webuploader方法
    public function webuploader(Request $request){
    	//对于上床文件的处理
    	//1、判断是否有文件上传成功
    	if ($request -> hasFile('file') && $request -> file('file') -> isValid()) {
    		//2、重命名文件
    		$filename = sha1($request -> file('file') -> getClientOriginalName() . time() . rand(1000,9999)) . '.' . $request -> file('file') -> getClientOriginalExtension();
    		//3、保存上传文件（过去临时文件的路径）
    		Storage::disk('public') -> put($filename,file_get_contents($request -> file('file') -> path()));
    		//4、给ajax一个响应应答
    		return response() -> json([
    			'errorCode'		=>	'0',
    			'message'		=>	'文件上传成功！',
    			'path'			=>	'/storage/' . $filename
    		]);
    	} else {
    		//4、给ajax一个响应应答
    		return response() -> json([
    			'errorCode'		=>	'1',
    			'message'		=>	$request -> file('file') -> getErrorMessage()
    		]);
    	}
    	
>>>>>>> loong
    }
}
